package me.dz.dreamcleaner.listener;

import catserver.api.bukkit.event.ForgeEvent;
import com.mohistmc.api.event.BukkitHookForgeEvent;
import com.pixelmonmod.pixelmon.api.events.spawning.SpawnEvent;
import com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon;
import me.dz.dreamcleaner.manager.PokeType;
import net.minecraft.entity.Entity;
import net.minecraftforge.fml.common.eventhandler.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.HashMap;

import static me.dz.dreamcleaner.DreamCleaner.*;

public class PokeEvent {

    public static HashMap<EntityPixelmon,Long> pokes = new HashMap<>();

    public static void canClear(EntityPixelmon pixelmon){
        if (!pokeShiny && pixelmon.getPokemonData().isShiny())return;
        if (pokeClear.contains(pixelmon.getSpecies().getNationalPokedexInteger() + "") ||
                pokeClear.contains(pixelmon.getSpecies().name))return;
        if (pixelmon.hasOwner())return;
        if (pixelmon.battleController != null)return;
        if (pixelmon.getPokemonData().isInRanch())return;
        if (pixelmon.getPokemonData().isEgg())return;
        for (PokeType type : pokeTypes){
            if (type.canClear(pixelmon))return;
        }
        pokes.put(pixelmon,System.currentTimeMillis() + (pokeLike * 1000));
    }

    public static void canClearEvent(Event event){
        if (!pokeEnable)return;
        if (event instanceof SpawnEvent){
            SpawnEvent e = (SpawnEvent) event;
            if (e.isCanceled())return;
            Entity entity = e.action.getOrCreateEntity();
            if (entity instanceof EntityPixelmon){
                canClear((EntityPixelmon) entity);
            }
        }
    }

    public static class CatServer implements Listener{
        @EventHandler
        public void onPoke(ForgeEvent event){
            canClearEvent(event.getForgeEvent());
        }
    }

    public static class Mohist implements Listener{
        @EventHandler
        public void onPoke(BukkitHookForgeEvent event){
            canClearEvent(event.getEvent());
        }
    }
}
